<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>FinData - 仪表盘</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            font-family: 'Arial', sans-serif;
            background-color: #0a0a0a;
            color: #e0e0e0;
        }
        .header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 15px 30px;
            background-color: #121212;
            border-bottom: 1px solid #333;
        }
        .logo-container {
            display: flex;
            align-items: center;
        }
        .logo {
            width: 40px;
            height: 40px;
            margin-right: 10px;
            filter: drop-shadow(0 0 5px rgba(138, 43, 226, 0.7));
            animation: pulse 2s infinite alternate;
        }
        .logo-text {
            font-size: 24px;
            font-weight: bold;
            background: linear-gradient(90deg, #8a2be2, #a855f7, #c084fc);
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
            text-shadow: 0 0 10px rgba(168, 85, 247, 0.5);
            animation: shine 3s linear infinite;
            margin-right: auto;
        }
        .nav-container {
            display: flex;
            gap: 20px;
        }
        .nav-item {
            position: relative;
            padding: 10px 20px;
            background: linear-gradient(145deg, #1e1e1e, #2a2a2a);
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.3s ease;
            color: #e0e0e0;
            overflow: hidden;
            z-index: 1;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .nav-item::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: linear-gradient(45deg, #8a2be2, #00bfff);
            z-index: -1;
            opacity: 0;
            transition: opacity 0.3s ease;
        }
        .nav-item:hover {
            transform: translateY(-3px);
            box-shadow: 0 6px 12px rgba(138, 43, 226, 0.3);
            color: white;
        }
        .nav-item:hover::before {
            opacity: 1;
        }
        .nav-item::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 50%;
            width: 0;
            height: 3px;
            background: #4CAF50;
            transition: all 0.3s ease;
        }
        .nav-item:hover::after {
            width: 70%;
            left: 15%;
        }
        .logout-btn {
            position: relative;
            padding: 10px 20px;
            background: linear-gradient(145deg, #F44336, #D32F2F);
            border-radius: 8px;
            color: white;
            font-weight: 500;
            cursor: pointer;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
            overflow: hidden;
            z-index: 1;
        }
        .logout-btn::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
            transition: all 0.5s ease;
            z-index: -1;
        }
        .logout-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 6px 12px rgba(244, 67, 54, 0.5);
        }
        .logout-btn:hover::before {
            left: 100%;
        }
        .welcome-message {
            text-align: center;
            margin: 50px auto;
            font-size: 2rem;
            background: linear-gradient(90deg, #8a2be2, #00bfff);
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
            max-width: 800px;
        }
        .user-info {
            background-color: rgba(18, 18, 18, 0.8);
            border-radius: 10px;
            padding: 20px;
            margin: 30px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .user-info h2 {
            margin-top: 0;
            color: #a855f7;
        }
        .index-summary {
            display: flex;
            flex-direction: column;
            gap: 30px;
            margin: 30px;
        }
        .index-card {
            width: auto;
            height: 250px;
            background-color: #121212;
            border-radius: 12px;
            padding: 30px;
            box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
            transition: all 0.3s ease;
            cursor: pointer;
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            position: relative;
            overflow: hidden;
            border-left: 4px solid #8a2be2;
            margin-bottom: 20px;
        }
        .index-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 12px 24px rgba(0, 0, 0, 0.6);
            background-color: #161616;
        }
        .index-name {
            font-size: 28px;
            margin-bottom: 15px;
            color: #e0e0e0;
            display: flex;
            align-items: center;
            gap: 15px;
        }
        .market-status {
            font-size: 14px;
            padding: 4px 12px;
            border-radius: 20px;
            background-color: rgba(18, 18, 18, 0.6);
            white-space: nowrap;
        }
        .status-closed {
            color: #bfbfbf;
            border: 1px solid rgba(191, 191, 191, 0.3);
        }
        .status-open {
            color: #52c41a;
            border: 1px solid rgba(82, 196, 26, 0.3);
        }
        .status-non-trading {
            color: #ff9800;
            border: 1px solid rgba(255, 152, 0, 0.3);
        }
        .index-price {
            font-size: 42px;
            font-weight: bold;
            margin-bottom: 15px;
            letter-spacing: -1px;
        }
        .index-change {
            display: flex;
            align-items: center;
            font-size: 20px;
            margin-bottom: 20px;
            gap: 8px;
        }
        .index-extra {
            display: flex;
            gap: 40px;
            margin-top: 15px;
        }
        .index-extra-item {
            display: flex;
            flex-direction: column;
        }
        .extra-label {
            font-size: 13px;
            margin-bottom: 6px;
            color: #888;
        }
        .extra-value {
            font-size: 16px;
            font-weight: 500;
            color: #e0e0e0;
        }
        .data-source {
            text-align: right;
            font-size: 12px;
            color: #666;
            margin: 5px 0;
        }
        .index-link {
            color: inherit;
            text-decoration: none;
            width: 100%;
        }
        .qr-hint {
            display: flex;
            align-items: center;
            font-size: 12px;
            color: #888;
        }
        .qr-icon {
            width: 16px;
            height: 16px;
            margin-right: 5px;
        }
        .index-left {
            display: flex;
            flex-direction: column;
            flex: 1;
        }
        .index-right {
            text-align: right;
            padding-left: 20px;
            display: flex;
            flex-direction: column;
            align-items: flex-end;
        }
        .index-time {
            font-size: 14px;
            color: #888;
            margin-top: 10px;
        }
        .index-up {
            color: #ff4d4f;
        }
        .index-down {
            color: #52c41a;
        }
        .data-controls {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin: 0 30px 80px;
            gap: 15px;
        }
        .refresh-btn {
            padding: 10px 20px;
            background: linear-gradient(145deg, #4CAF50, #2E7D32);
            border-radius: 8px;
            color: white;
            font-weight: 500;
            cursor: pointer;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 8px;
            position: relative;
            overflow: hidden;
            z-index: 1;
        }
        .refresh-btn::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
            transition: all 0.5s ease;
            z-index: -1;
        }
        .refresh-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 6px 12px rgba(76, 175, 80, 0.5);
        }
        .refresh-btn:hover::before {
            left: 100%;
        }
        .refresh-btn:hover .refresh-icon {
            animation: spin 1s ease-in-out;
        }
        .refresh-btn.disabled {
            background: linear-gradient(145deg, #9E9E9E, #757575);
            cursor: not-allowed;
            transform: none;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        .refresh-icon {
            width: 16px;
            height: 16px;
            transition: all 0.3s ease;
        }
        .update-status {
            font-size: 14px;
            color: #888;
        }
        .market-closed-alert {
            color: #ff9800;
            font-size: 14px;
            margin-top: 5px;
            display: none;
        }
        .non-trading-day-alert {
            background-color: rgba(255, 152, 0, 0.2);
            color: #ff9800;
            padding: 10px 20px;
            border-radius: 8px;
            text-align: center;
            margin: 20px 30px;
            border: 1px solid rgba(255, 152, 0, 0.3);
            display: none;
        }
        .index-card-up {
            border-left: 4px solid #ff4d4f;
        }
        .index-card-down {
            border-left: 4px solid #52c41a;
        }
        
        /* 添加动画关键帧 */
        @keyframes pulse {
            0% {
                transform: scale(1);
                opacity: 0.8;
            }
            100% {
                transform: scale(1.1);
                opacity: 1;
                filter: drop-shadow(0 0 10px rgba(138, 43, 226, 0.9));
            }
        }
        
        @keyframes shine {
            to {
                background-position: 200% center;
            }
        }
        
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        /* 版权信息样式 */
        .copyright-container {
            background-color: rgba(18, 18, 18, 0.8);
            padding: 15px;
            margin-top: 30px;
            text-align: center;
            border-top: 1px solid #333;
            position: fixed;
            bottom: 0;
            left: 0;
            width: 100%;
            z-index: 100;
        }
        
        .copyright {
            font-size: 12px;
            color: #666;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="logo-container">
            <svg class="logo" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg">
                <path d="M20 0 L40 20 L20 40 L0 20 Z" fill="#8a2be2"/>
                <path d="M10 10 L30 10 L30 30 L10 30 Z" fill="#00bfff"/>
                <path d="M15 15 L25 15 L25 25 L15 25 Z" fill="#4CAF50"/>
            </svg>
            <div class="logo-text">FinData</div>
        </div>
        
        <div class="nav-container">
            <div class="nav-item" id="favoritesBtn">自选</div>
            <div class="nav-item" onclick="window.location.href='/data'">数据</div>
            <div class="nav-item" id="backTestBtn">回测</div>
            <a class="nav-item" href="/forum" style="text-decoration: none;">论坛</a>
            <div class="logout-btn" id="logoutBtn">登出</div>
        </div>
    </div>

    <div class="welcome-message">
        欢迎回来！<span id="username"></span>
    </div>

    <div class="user-info">
        <h2>账户信息</h2>
        <p>上次登录时间: <span id="lastLogin">正在加载...</span></p>
    </div>

    <div class="non-trading-day-alert" id="nonTradingDayAlert">
        今日非交易日
    </div>

    <div class="index-summary">
        <a href="https://gu.qq.com/sh000001/zs" target="_blank" class="index-link">
            <div class="index-card" id="sh000001-card">
                <div class="index-left">
                    <div class="index-name">
                        上证指数 (000001.SH)
                        <div class="market-status status-closed" id="sh000001-status">已收盘</div>
                    </div>
                    <div class="index-price" id="sh000001-price">--</div>
                    <div class="index-change">
                        <span class="index-change-value" id="sh000001-change">--</span>
                        <span class="index-change-percent" id="sh000001-percent">--</span>
                    </div>
                    <div class="index-extra">
                        <div class="index-extra-item">
                            <span class="extra-label">成交量</span>
                            <span class="extra-value" id="sh000001-volume">--</span>
                        </div>
                        <div class="index-extra-item">
                            <span class="extra-label">成交额</span>
                            <span class="extra-value" id="sh000001-amount">--</span>
                        </div>
                    </div>
                </div>
                <div class="index-right">
                    <div class="index-time" id="sh000001-time">更新时间: --</div>
                    <div class="qr-hint">
                        <svg class="qr-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                            <path d="M3 11V3H11V11H3Z" stroke="currentColor" stroke-width="2"/>
                            <path d="M3 21V13H11V21H3Z" stroke="currentColor" stroke-width="2"/>
                            <path d="M13 11V3H21V11H13Z" stroke="currentColor" stroke-width="2"/>
                            <path d="M13 21V13H21V13" stroke="currentColor" stroke-width="2"/>
                            <path d="M16 18H18V16" stroke="currentColor" stroke-width="2"/>
                            <path d="M21 21V21" stroke="currentColor" stroke-width="2"/>
                        </svg>
                        点击查看详情
                    </div>
                </div>
            </div>
        </a>
        <a href="https://gu.qq.com/sz399001/zs" target="_blank" class="index-link">
            <div class="index-card" id="sz399001-card">
                <div class="index-left">
                    <div class="index-name">
                        深证成指 (399001.SZ)
                        <div class="market-status status-closed" id="sz399001-status">已收盘</div>
                    </div>
                    <div class="index-price" id="sz399001-price">--</div>
                    <div class="index-change">
                        <span class="index-change-value" id="sz399001-change">--</span>
                        <span class="index-change-percent" id="sz399001-percent">--</span>
                    </div>
                    <div class="index-extra">
                        <div class="index-extra-item">
                            <span class="extra-label">成交量</span>
                            <span class="extra-value" id="sz399001-volume">--</span>
                        </div>
                        <div class="index-extra-item">
                            <span class="extra-label">成交额</span>
                            <span class="extra-value" id="sz399001-amount">--</span>
                        </div>
                    </div>
                </div>
                <div class="index-right">
                    <div class="index-time" id="sz399001-time">更新时间: --</div>
                    <div class="qr-hint">
                        <svg class="qr-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                            <path d="M3 11V3H11V11H3Z" stroke="currentColor" stroke-width="2"/>
                            <path d="M3 21V13H11V21H3Z" stroke="currentColor" stroke-width="2"/>
                            <path d="M13 11V3H21V11H13Z" stroke="currentColor" stroke-width="2"/>
                            <path d="M13 21V13H21V13" stroke="currentColor" stroke-width="2"/>
                            <path d="M16 18H18V16" stroke="currentColor" stroke-width="2"/>
                            <path d="M21 21V21" stroke="currentColor" stroke-width="2"/>
                        </svg>
                        点击查看详情
                    </div>
                </div>
            </div>
        </a>
    </div>

    <div class="data-controls">
        <div class="update-status" id="updateStatus">上次更新: --</div>
        <div class="refresh-btn" id="refreshBtn">
            <svg class="refresh-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M17.65 6.35C16.2 4.9 14.21 4 12 4C7.58 4 4.01 7.58 4.01 12C4.01 16.42 7.58 20 12 20C15.73 20 18.84 17.45 19.73 14H17.65C16.83 16.33 14.61 18 12 18C8.69 18 6 15.31 6 12C6 8.69 8.69 6 12 6C13.66 6 15.14 6.69 16.22 7.78L13 11H20V4L17.65 6.35Z" fill="currentColor"/>
            </svg>
            刷新数据
        </div>
        <div class="market-closed-alert" id="marketClosedAlert"></div>
        <div class="data-source">数据来源: 腾讯财经</div>
    </div>

    <!-- 页面底部的版权信息已经通过copyright-container添加 -->
    
    <script>
        // 页面加载时获取用户信息
        document.addEventListener('DOMContentLoaded', async function() {
            try {
                const response = await fetch('/api/user-info');
                if (response.ok) {
                    const userData = await response.json();
                    
                    // 显示用户名
                    document.getElementById('username').textContent = userData.username;
                    
                    // 格式化并显示上次登录时间
                    if (userData.lastLogin) {
                        const lastLoginDate = new Date(userData.lastLogin);
                        // 检查是否是今天的日期，如果是则可能是本次登录时间
                        const today = new Date();
                        const isToday = lastLoginDate.getDate() === today.getDate() &&
                                        lastLoginDate.getMonth() === today.getMonth() &&
                                        lastLoginDate.getFullYear() === today.getFullYear();
                        
                        if (isToday) {
                            // 如果是今天的登录，显示为"今天 HH:MM:SS"
                            document.getElementById('lastLogin').textContent = 
                                `今天 ${lastLoginDate.toLocaleTimeString()}`;
                        } else {
                            // 如果不是今天的登录，显示完整日期时间
                            document.getElementById('lastLogin').textContent = 
                                lastLoginDate.toLocaleString();
                        }
                    } else {
                        document.getElementById('lastLogin').textContent = '首次登录';
                    }
                } else {
                    // 如果获取用户信息失败，可能是未登录状态
                    console.error('获取用户信息失败，状态码:', response.status);
                    // 不要自动重定向，而是显示错误信息
                    document.getElementById('username').textContent = '获取用户信息失败';
                    document.getElementById('lastLogin').textContent = '请尝试重新登录';
                }
            } catch (error) {
                console.error('获取用户信息失败:', error);
                document.getElementById('username').textContent = '获取用户信息失败';
                document.getElementById('lastLogin').textContent = '请尝试重新登录';
            }
            
            // 加载交易日历
            await loadTradingCalendar();
            
            // 初始化股指数据
            fetchStockIndexData();
            
            // 设置自动更新定时器（每分钟更新一次）
            setInterval(fetchStockIndexData, 60000);
        });
        
        // 登出功能
        document.getElementById('logoutBtn').addEventListener('click', async function() {
            try {
                const response = await fetch('/api/logout', {
                    method: 'POST',
                    credentials: 'include'
                });
                
                if (response.ok) {
                    // 登出成功，重定向到首页
                    window.location.href = '/blank';
                } else {
                    alert('登出失败，请重试');
                }
            } catch (error) {
                console.error('登出请求错误:', error);
                alert('网络请求失败，请检查您的网络连接');
            }
        });
        
        // 自选按钮点击事件
        document.getElementById('favoritesBtn').addEventListener('click', function() {
            window.location.href = '/favorites';
        });
        
        // 回测按钮点击事件
        document.getElementById('backTestBtn').addEventListener('click', function() {
            window.location.href = '/backtest';
        });
        
        // 刷新按钮点击事件
        document.getElementById('refreshBtn').addEventListener('click', fetchStockIndexData);
        
        // 获取股指数据
        async function fetchStockIndexData() {
            try {
                // 检查是否为交易时间
                const now = new Date();
                const hour = now.getHours();
                const minute = now.getMinutes();
                const isMarketOpen = (hour === 9 && minute >= 30) || (hour > 9 && hour < 11) || 
                                   (hour === 11 && minute <= 30) || 
                                   (hour >= 13 && hour < 15);
                
                const isTrading = checkTradingDay();
                const refreshBtn = document.getElementById('refreshBtn');
                const marketClosedAlert = document.getElementById('marketClosedAlert');
                
                if (!isTrading) {
                    // 非交易日
                    marketClosedAlert.style.display = 'block';
                    marketClosedAlert.textContent = '今日为非交易日，数据无法刷新';
                    refreshBtn.classList.add('disabled');
                } else if (!isMarketOpen) {
                    // 交易日但不在交易时间
                    marketClosedAlert.style.display = 'block';
                    marketClosedAlert.textContent = '当前为非交易时段，数据为收盘数据';
                    refreshBtn.classList.add('disabled');
                } else {
                    // 交易时间
                    marketClosedAlert.style.display = 'none';
                    refreshBtn.classList.remove('disabled');
                }
                
                // 添加时间戳防止缓存
                const timestamp = new Date().getTime();
                const url = `https://qt.gtimg.cn/?q=s_sh000001,s_sz399001&_=${timestamp}`;
                
                // 使用代理接口获取数据
                const response = await fetch(`/api/stock-proxy?url=${encodeURIComponent(url)}`);
                if (!response.ok) {
                    throw new Error('获取指数数据失败');
                }
                
                const data = await response.text();
                processStockData(data);
                
                // 更新刷新时间
                document.getElementById('updateStatus').textContent = `上次更新: ${now.toLocaleTimeString()}`;
            } catch (error) {
                console.error('获取股指数据错误:', error);
            }
        }
        
        // 处理股指数据
        function processStockData(data) {
            // 检查是否为交易日
            const isTrading = checkTradingDay();
            const nonTradingDayAlert = document.getElementById('nonTradingDayAlert');
            
            if (!isTrading) {
                nonTradingDayAlert.style.display = 'block';
            } else {
                nonTradingDayAlert.style.display = 'none';
            }
            
            // 解析数据
            try {
                // 提取上证指数数据
                const shMatch = data.match(/v_s_sh000001="([^"]+)"/);
                if (shMatch && shMatch[1]) {
                    const shData = shMatch[1].split('~');
                    updateIndexCard('sh000001', shData, isTrading);
                }
                
                // 提取深证成指数据
                const szMatch = data.match(/v_s_sz399001="([^"]+)"/);
                if (szMatch && szMatch[1]) {
                    const szData = szMatch[1].split('~');
                    updateIndexCard('sz399001', szData, isTrading);
                }
            } catch (error) {
                console.error('处理股指数据错误:', error);
            }
        }
        
        // 更新指数卡片
        function updateIndexCard(indexId, data, isTrading) {
            // 数据格式根据腾讯财经API:
            // 上证指数: 1~上证指数~000001~价格~涨跌~涨跌%~成交量(手)~成交额(万元)~~总市值~指数类型
            // 深证成指: 51~深证成指~399001~价格~涨跌~涨跌%~成交量(手)~成交额(万元)~~总市值~指数类型
            
            const price = document.getElementById(`${indexId}-price`);
            const change = document.getElementById(`${indexId}-change`);
            const percent = document.getElementById(`${indexId}-percent`);
            const volume = document.getElementById(`${indexId}-volume`);
            const amount = document.getElementById(`${indexId}-amount`);
            const time = document.getElementById(`${indexId}-time`);
            const status = document.getElementById(`${indexId}-status`);
            const card = document.getElementById(`${indexId}-card`);
            
            if (!isTrading) {
                status.textContent = '非交易日';
                status.className = 'market-status status-non-trading';
                return;
            }
            
            // 判断是否交易时间
            const now = new Date();
            const hour = now.getHours();
            const minute = now.getMinutes();
            const isMarketOpen = (hour === 9 && minute >= 30) || (hour > 9 && hour < 11) || 
                               (hour === 11 && minute <= 30) || 
                               (hour >= 13 && hour < 15);
            
            if (isMarketOpen) {
                status.textContent = '交易中';
                status.className = 'market-status status-open';
            } else {
                status.textContent = '已收盘';
                status.className = 'market-status status-closed';
            }
            
            // 更新价格和涨跌幅
            const priceValue = parseFloat(data[3]);
            const changeValue = parseFloat(data[4]);
            const percentValue = parseFloat(data[5]);
            
            price.textContent = priceValue.toFixed(2);
            change.textContent = (changeValue >= 0 ? '+' : '') + changeValue.toFixed(2);
            percent.textContent = '(' + (percentValue >= 0 ? '+' : '') + percentValue.toFixed(2) + '%)';
            
            // 设置涨跌颜色
            if (changeValue > 0) {
                price.className = 'index-price index-up';
                change.className = 'index-change-value index-up';
                percent.className = 'index-change-percent index-up';
                card.className = 'index-card index-card-up';
            } else if (changeValue < 0) {
                price.className = 'index-price index-down';
                change.className = 'index-change-value index-down';
                percent.className = 'index-change-percent index-down';
                card.className = 'index-card index-card-down';
            } else {
                price.className = 'index-price';
                change.className = 'index-change-value';
                percent.className = 'index-change-percent';
                card.className = 'index-card';
            }
            
            // 更新成交量和成交额
            const volumeValue = parseInt(data[6]);
            const amountValue = parseInt(data[7]) / 10000; // 转换为亿元
            
            volume.textContent = formatLargeNumber(volumeValue) + '手';
            amount.textContent = amountValue.toFixed(2) + '亿元';
            
            // 更新时间
            time.textContent = '更新时间: ' + now.toLocaleString();
        }
        
        // 格式化大数字
        function formatLargeNumber(num) {
            if (num >= 100000000) {
                return (num / 100000000).toFixed(2) + '亿';
            } else if (num >= 10000) {
                return (num / 10000).toFixed(2) + '万';
            } else {
                return num.toString();
            }
        }
        
        // 交易日历数据
        const tradingDays = [];
        
        // 初始化加载交易日历
        async function loadTradingCalendar() {
            try {
                // 直接从CSV文件加载交易日历数据
                const response = await fetch('/交易日历.csv');
                if (response.ok) {
                    const csvText = await response.text();
                    // 解析CSV文件，第一行是标题，忽略
                    const lines = csvText.split('\n').slice(1);
                    // 将每一行（每个交易日）添加到数组中
                    for (const line of lines) {
                        const date = line.trim();
                        if (date) {
                            tradingDays.push(date);
                        }
                    }
                    console.log(`交易日历加载成功，共${tradingDays.length}个交易日`);
                } else {
                    console.error('获取交易日历失败');
                }
            } catch (error) {
                console.error('加载交易日历错误:', error);
            }
        }
        
        // 检查是否为交易日
        function checkTradingDay() {
            const now = new Date();
            const day = now.getDay();
            
            // 周末不是交易日
            if (day === 0 || day === 6) {
                return false;
            }
            
            // 格式化当前日期为YYYY-MM-DD格式，用于与交易日历比对
            const year = now.getFullYear();
            const month = String(now.getMonth() + 1).padStart(2, '0');
            const date = String(now.getDate()).padStart(2, '0');
            const today = `${year}-${month}-${date}`;
            
            // 如果交易日历已加载，则检查当前日期是否在交易日历中
            if (tradingDays.length > 0) {
                return tradingDays.includes(today);
            }
            
            // 如果交易日历未加载，则仅根据周末判断
            return true;
        }
    </script>
    
    <!-- 版权信息 -->
    <div class="copyright-container">
        <div class="copyright">
            © 2023-2024 FinData. All Rights Reserved. 保留所有权利。
        </div>
    </div>
</body>
</html>